#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtSerialPort/QSerialPort>
#include <QLabel>
#include "lib/qcustomplot/qcustomplot.h"

#define GRAPH_PLOT                  3
#define TEMPERATURE_PORT_NUM        8
#define TEMPERATURE_DATA_MAXSIZE   30
#define TEMPERATURE_DATA_MINSIZE   6

namespace Ui {
class MainWindow;
}

class AxisTag;
class Console;
class SerialPortDialog;
class SerialPortCommunication;
class TemperaturePlotSettingsDialog;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    void initActionsConnections();
    void showStatusMessage(const QString &message);

    void initTemperaturePlot();

    void updataTemperature(const QByteArray &temperatureData);

private slots:
    void slotOpenSerialPort();
    void slotCloseSerialPort();
    void slotAbout();
    void slotWriteData(const QByteArray &data);
    void slotReadData();
    void slotHandleError(QSerialPort::SerialPortError error);

    void slotTimeout();
    void slotCopySerialPortSettings();

    void slotSerialPortConnected();

    void slotUpdatePlotSettings(int id);

private:
    Ui::MainWindow *ui;
    QLabel *m_serialportStatus;
    QLabel *m_temperatureRefreshStatus;
    QSerialPort *m_serialport;
    SerialPortDialog *m_serialportSettingsDlg;
    Console *m_console;
    SerialPortCommunication *m_communication;
    TemperaturePlotSettingsDialog *m_temperaturePlotSettingsDlg;
//    QSerialPort *m_serial;

    QCustomPlot *m_customPlot;
    QVector<QPointer<QCPGraph>> m_graph;
    QVector<AxisTag*> m_tag;
    QTimer m_dataTimer;

    QString *m_stringTemperatureData;
    double  *m_temperatureData;
    QMutex   m_mutex;

    double m_xAxisRange;
    int m_nPlot;
    int m_temperatureMIN;
    int m_temperatureMAX;
    int m_plotPeriod;
    bool m_demoChecked;
};

#endif // MAINWINDOW_H
